home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Extensions… / PostScript Extension Shell ƒ / PS Extension.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-20  |  8.0 KB  |  293 lines  |  [TEXT/MPS ]

  1. /*________________________________________________________
  2.  
  3.     File: PS Extension.c
  4.  
  5.     C code for a printing extension.
  6.  
  7.     Dave Hersey
  8.     Apple Developer Technical Support
  9.  
  10.     (Based on the "Extension Shell" sample.)
  11.  
  12.     12/01/92 - dmh - Created.
  13.      4/26/93 - dmh - Updated to use recommended approach
  14.                       to global data initialization.
  15.      9/05/93 - dmh - Updated for b2.
  16.                     - Fixed minor problem with highlighting
  17.                      of editText panel items.
  18.                    - Switched to Exception.h assertion stuff
  19.                      for error checking.
  20.      9/08/93 - dmh - Modified to override
  21.                       GXPostScriptDoPageSetup.
  22.                    - Added a "PS " before the file names.
  23.                    - Changed creator type.
  24.     12/18/93 - dmh - Updated for b3.
  25.      3/22/94 - dmh - Updated for b4.
  26.  
  27.     (Note: all functions are in the Mark menu.)
  28.     
  29. __________________________________________________________*/
  30.  
  31. #include "PS Extension.h"
  32.  
  33.  
  34. /*******************************************************************
  35.     InitGlobalData is used to initialize any global data we need to
  36.     in our initialize message override.  It's critical that you do
  37.     things this way, rather than access the data in the same scope
  38.     that you call NewMessageGlobals.  Otherwise, some compilers
  39.     will give you code that references an invalid A5 world.
  40.  
  41. ********************************************************************/
  42.  
  43. OSErr InitGlobalData()
  44. {
  45. // Initialize any global data here.
  46.     
  47.     return noErr;
  48. }
  49.  
  50.  
  51. /*******************************************************************
  52.     NewInitialize is our override for the GXInitialize message.  In
  53.     here, you shouldn't initialize anything directly-- call
  54.     InitGlobalData for that.  Once you create the A5 world with
  55.     NewMessageGlobals, you can access your global data just like
  56.     you were an application.  Whenever you're called, your global
  57.     data will be valid.
  58.     
  59. ********************************************************************/
  60.  
  61. OSErr NewInitialize()
  62. {
  63.     OSErr    err;
  64.  
  65. // Create an A5 world, and initialize our global data.
  66.  
  67.     err = NewMessageGlobals(A5Size(), A5Init);
  68.     
  69.     if (!err) err = InitGlobalData();
  70.     
  71.     return err;
  72. }
  73.  
  74.  
  75. /*******************************************************************
  76.     NewShutDown is our override for the GXShutDown message.  We
  77.     simply throw away our A5 world which we created in our
  78.     GXInitialize message override, NewInitialize.
  79.     
  80. ********************************************************************/
  81.  
  82. OSErr NewShutDown()
  83. {
  84.     DisposeMessageGlobals();
  85.     
  86.     return noErr;
  87. }
  88.  
  89.  
  90. /*******************************************************************
  91.     NewPSDoPageSetup is our override for the GXPostScriptDoPageSetup
  92.     message.  We check to see if we're enabled, and if so, give a
  93.     SysBeep before forwarding.
  94.     
  95. ********************************************************************/
  96.  
  97. OSErr NewPSDoPageSetup(gxFormat aFormat, long pageNum, gxPostScriptImageDataHdl aDataHdl)
  98. {
  99.     OSErr                    err;
  100.     ExtensionCollection        extCollect;
  101.     
  102. // Try to retrieve our collection item.  If we can't find it, we'll
  103. // act as if the user had us turned off or on (as determined by
  104. // kDefaultSetting).
  105.  
  106.     err = GetJobCollectionItem(&extCollect, nil, kExtensionCollectionType,
  107.                                gxPrintingTagID);
  108.  
  109.     if (err)
  110.     {
  111.         extCollect.extTurnedOn = kDefaultSetting;
  112.         err = noErr;
  113.     }
  114.  
  115.  
  116. // If we're turned on, beep so we know we've been here, then forward
  117. // this message down the chain.
  118.  
  119.     if (extCollect.extTurnedOn)
  120.         SysBeep(3);
  121.     
  122.     err = Forward_GXPostScriptDoPageSetup(aFormat, pageNum, aDataHdl);
  123.  
  124.     return err;
  125. }
  126.  
  127.  
  128. /*******************************************************************
  129.     NewJobPrintDialog is our override for GXJobPrintDialog.  All we
  130.     do is set up our panel and then forward the message.
  131.     
  132. ********************************************************************/
  133.  
  134. OSErr NewJobPrintDialog(gxDialogResult *dlogResult)
  135. {
  136.     OSErr    err;
  137.     
  138.     err = SetUpPrintPanel();
  139.  
  140.     if (!err)
  141.         err = Forward_GXJobPrintDialog(dlogResult);
  142.     
  143.     return err;
  144. }
  145.  
  146.  
  147. /*******************************************************************
  148.     NewHandlePanelEvent is our override for GXHandlePanelEvent. If
  149.     the event is one of ours, we handle it.  Otherwise, we just
  150.     forward it down the chain.
  151.     
  152. ********************************************************************/
  153.  
  154. OSErr NewHandlePanelEvent(gxPanelInfoRecord *panelInfo)
  155. {
  156.     OSErr            err = noErr;
  157.     GrafPtr            oldPort;
  158.     DialogPtr        pDlg;
  159.  
  160. // Get a pointer to the dialog, save our current grafPort,
  161. // and set us to the dialog's port.
  162.  
  163.     pDlg = panelInfo->pDlg;
  164.     GetPort(&oldPort);
  165.     SetPort(pDlg);
  166.  
  167.     switch (panelInfo->panelEvt)    // Handle any of these events as need be.
  168.     {
  169.         case gxPanelOpenEvt:                // Initialize and draw.
  170.             break;
  171.         case gxPanelCloseEvt:                // Your panel is going away (panel switch,
  172.             break;                            // confirm or cancel).
  173.  
  174.         case gxPanelHitEvt:                    // There's a hit in your panel.
  175.             break;
  176.         case gxPanelFilterEvt:                // This is called to filter every event.
  177.             break;
  178.         case gxPanelCancelEvt:                // The user has cancelled the dialog.
  179.             break;
  180.         case gxPanelConfirmEvt:                // The user has confirmed the dialog.
  181.             break;
  182.         case gxPanelUserWillConfirmEvt:        // user has selected confirm, time to
  183.             break;                            // parse your panel interdependencies.
  184.                                         
  185.         case gxPanelDialogEvt:                // Event to be handled by dialoghandler
  186.             break;                            // (you get to see all events).
  187.  
  188.         case gxPanelOtherEvt:                // osEvts, etc.
  189.             break;
  190.  
  191. // If our panel is activating/deactivating or if the focus (which
  192. // section of the dialog is active) has changed we need to activate
  193. // our editText fields appropriately.
  194.  
  195.         case gxPanelActivateEvt:            // The dialog window has just become active.
  196.         case gxPanelDeactivateEvt:            // The dialog window is becoming inactive.
  197.         case gxPanelIconFocusEvt:            // The user is moving to the icon list.
  198.         case gxPanelPanelFocusEvt:            // The user is moving to the panel.
  199.  
  200. /*  Here's what you would do if you had an editText field at DITL item #5:
  201.  
  202. #define d_edText    5
  203.  
  204.             if ((((DialogPeek) pDlg)->editField +1) == (panelInfo->itemCount +d_edText))
  205.             {
  206.                 if (panelInfo->panelEvt == gxPanelPanelFocusEvt)
  207.                     TEActivate(((DialogPeek) pDlg)->textH);
  208.                 else
  209.                     TEDeactivate(((DialogPeek) pDlg)->textH);
  210.             }
  211. */
  212.             break;
  213.     }
  214.  
  215. // Restore the original port as we leave.
  216.  
  217.     SetPort(oldPort);
  218.     return err;
  219. }
  220.  
  221.  
  222. /*******************************************************************
  223.     SetUpPrintPanel sets up our print panel, adding a default
  224.     ExtensionCollection item to the job collection.  This
  225.     collection item has the values we'll use to set up our panel's
  226.     controls.
  227.     
  228. ********************************************************************/
  229.  
  230. OSErr SetUpPrintPanel()
  231. {
  232.     OSErr                    err;
  233.     gxPanelSetupRecord        panelSetupRec;
  234.     ExtensionCollection        extConfig;
  235.  
  236. // Try to find our collection item.
  237.  
  238.     err = GetCollectionItem(GXGetJobCollection(GXGetJob()),
  239.                             kExtensionCollectionType,
  240.                             gxPrintingTagID,
  241.                             nil,
  242.                             &extConfig);
  243.  
  244.  
  245. // If we don't have an item in the job collection yet, store our default
  246. // settings in it.
  247.  
  248.     if (err == collectionItemNotFoundErr)
  249.     {
  250.         extConfig.extTurnedOn = kDefaultSetting;
  251.     
  252.         err = AddCollectionItem(GXGetJobCollection(GXGetJob()),
  253.                                 kExtensionCollectionType,
  254.                                 gxPrintingTagID,
  255.                                 sizeof(ExtensionCollection),
  256.                                 &extConfig);
  257.  
  258.         nrequire(err, HaveCollectionMgrError);
  259.     }
  260.  
  261.  
  262. // Now, set up the panel.
  263.  
  264.     panelSetupRec.panelResId        = r_ExtensionPanel;        // which panel resource?
  265.     panelSetupRec.resourceRefNum    = GXGetMessageHandlerResFile(); // where is it?
  266.     panelSetupRec.refCon            = 0;                       // we don't use this.
  267.     panelSetupRec.panelKind            = gxExtensionPanel;     // This is an extension panel.
  268.  
  269.     err = GXSetupDialogPanel(&panelSetupRec);
  270.  
  271.  
  272. HaveCollectionMgrError:
  273.     
  274.     return err;
  275. }
  276.  
  277.  
  278. /*******************************************************************
  279.     GetJobCollectionItem is a generic routine that retrieves a
  280.     collection item from the job collection.
  281.     
  282. ********************************************************************/
  283.  
  284. OSErr GetJobCollectionItem(void *collectItem, long *collectSize,
  285.                            OSType collectType, short collectID)
  286. {
  287.     return GetCollectionItem(GXGetJobCollection(GXGetJob()),
  288.                              collectType,
  289.                              collectID,
  290.                              collectSize,
  291.                              collectItem);
  292. }
  293.